<script type="text/javascript">
    var time_left = Array();
    var timerId = Array();
    var initiate = Array();
</script>
<header class="index clearfix">
    <ul>
        <li class="register"><?php echo $this->Html->link('Register Now', array('controller' => 'users', 'action' => 'register'), array('class' => 'registration')); ?></li>
        <li class="soldfor"></li>
    </ul>
</header>
<h3 class="mainbar">Auctions - New products with full warranty</h3>
<div class="contentIndex clearfix">
    <ul class="auction">   
<?php foreach($products as $product) : ?>
        <?php if ($product['Auction']['time_left'] == 0) :?>
        <li class="sold">
        <?php else: ?>
        <li>
        <?php endif; ?>
            <ul class="aucinfo">
            <li><h2><?php echo $this->Html->link($product['Product']['name'], array('controller' => 'products', 'action' => 'view', $product['Product']['id'])); ?></h2></li>
            <li><?php echo $this->Html->link(
                $this->Html->image($product['Product']['img'], array('alt' => $product['Product']['name'], 'class' => 'productImage')),
                array('controller' => 'products', 'action' => 'view', $product['Product']['id']),
                array('escape' => false)
                ); ?></li>
            <li><span class="countdown" id="countdownbid<?php echo $product['Product']['id']; ?>"><?php echo $product['Auction']['time_left'];?></span></li>
            <li class="price">S$<span id="pricebid<?php echo $product['Product']['id']; ?>"><?php echo $product['Auction']['currentBid']; ?></span></li>
            <li><span class="bidder" id="bidderbid<?php echo $product['Product']['id']; ?>"><?php echo $product['Auction']['currentBidder']; ?></span></li>
            <?php echo $this->Form->hidden('productbid'. $product['Product']['id'], array('default' => $product['Product']['id'])); ?>
            <?php echo $this->Form->hidden('auctionbid'. $product['Product']['id'], array('default' => $product['Auction']['id'])); ?>
            <?php if ($product['Auction']['time_left'] == 0) :
                echo $this->Form->submit('Sold', array('class' => 'justsold'));
            else:
                echo $this->Form->submit('Bid', array('id' => 'bid' . $product['Product']['id'], 'class' => 'bid'));
            endif; ?>
<script type="text/javascript">
    time_left.push(time_left['bid' + <?php echo $product['Product']['id']; ?>]);
    timerId.push(time_left['bid' + <?php echo $product['Product']['id']; ?>]);
    time_left['bid' + <?php echo $product['Product']['id']; ?>] = <?php echo $product['Auction']['time_left']; ?>;
    initiate.push(<?php echo $product['Product']['id']; ?>);
</script>
            </ul>
        </li>
<?php endforeach; ?>
    </ul>
    <div class="paging">
    <?php
        echo $this->Paginator->prev(' << Previous', null, null, array('class' => 'disabled'));
        echo $paginator->numbers();
        echo $this->Paginator->next(' Next >>', array('id' => 'next'), null, array('class' => 'disabled'));
    ?>
    </div>
</div>
<script type="text/javascript">
    var user = "<?php echo $this->Session->read('Auth.User.username'); ?>";
    var token = "<?php echo $token['User']['token']; ?>";
    var pages = "<?php echo $this->Paginator->counter(array('format' => '%pages%')); ?>";
</script>
